﻿using System;
using System.Linq;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace RefOffPDA
{
    /*
     * Class: SendOff
     * 
     * Use: Form displaying all players currently on the pitch for the 
     *      relevant team, to indicate who is being sent off
     *      
     * Author: Mike Skaife, mcs3@aber.ac.uk
     */      
    public partial class SendOff : Form
    {
        //The current Match object
        Match theMatch;

        //Variable indicating whether the sending off is for the home
        //or away team
        String homeOrAway;

        //id of the player being sent off
        int player_id;

        public SendOff(Match match, String homeAway)
        {
            InitializeComponent();
            theMatch = match;
            homeOrAway = homeAway;
        }

        //This method displays the screen showing the disciplinary codes for the
        //sending off
        private void sendOffPlayer()
        {
            //Indicate the player being sent off and which team they play for
            theMatch.sendOffCode.player_id = player_id;
            theMatch.sendOffCode.homeOrAway = homeOrAway;

            //Hide this form and display the disciplinary codes
            theMatch.sendOffCode.Visible = true;
            this.Visible = false;
        }

        //This method is run when the first player in the team is being sent off
        private void SendOffPlayer1Btn_Click(object sender, EventArgs e)
        {
            //Get hold of the id of the player being sent off, from the button that
            //was clicked
            player_id = Int32.Parse(SendOffPlayer1Btn.Tag.ToString());

            //This code is run if the home team are having a player sent off
            if (homeOrAway.Equals("home"))
            {
                //Indicate which buttons on other screens need to be updated
                //to reflect the sending off
                theMatch.sendOffCode.sendOffButton = this.SendOffPlayer1Btn;
                theMatch.sendOffCode.goalButton = theMatch.homeGoal.GoalPlayer1Btn;
                theMatch.sendOffCode.cautionButton = theMatch.homeCaution.CautionPlayer1Btn;
                theMatch.sendOffCode.subOffButton = theMatch.homeSubOff.SubOffPlayer1Btn;
            }
            //This code is run if the away team are having a player sent off
            else
            {
                //Indicate which buttons on other screens need to be updated
                //to reflect the sending off
                theMatch.sendOffCode.sendOffButton = this.SendOffPlayer1Btn;
                theMatch.sendOffCode.goalButton = theMatch.awayGoal.GoalPlayer1Btn;
                theMatch.sendOffCode.cautionButton = theMatch.awayCaution.CautionPlayer1Btn;
                theMatch.sendOffCode.subOffButton = theMatch.awaySubOff.SubOffPlayer1Btn;
            }
            
            //Carry out the actual sending off
            sendOffPlayer();            
        }

        //This method is run when the second player in the team is being sent off
        private void SendOffPlayer2Btn_Click(object sender, EventArgs e)
        {
            //Get hold of the id of the player being sent off, from the button that
            //was clicked
            player_id = Int32.Parse(SendOffPlayer2Btn.Tag.ToString());

            //This code is run if the home team are having a player sent off
            if (homeOrAway.Equals("home"))
            {
                //Indicate which buttons on other screens need to be updated
                //to reflect the sending off
                theMatch.sendOffCode.sendOffButton = this.SendOffPlayer2Btn;
                theMatch.sendOffCode.goalButton = theMatch.homeGoal.GoalPlayer2Btn;
                theMatch.sendOffCode.cautionButton = theMatch.homeCaution.CautionPlayer2Btn;
                theMatch.sendOffCode.subOffButton = theMatch.homeSubOff.SubOffPlayer2Btn;
            }
            //This code is run if the away team are having a player sent off
            else
            {
                //Indicate which buttons on other screens need to be updated
                //to reflect the sending off
                theMatch.sendOffCode.sendOffButton = this.SendOffPlayer2Btn;
                theMatch.sendOffCode.goalButton = theMatch.awayGoal.GoalPlayer2Btn;
                theMatch.sendOffCode.cautionButton = theMatch.awayCaution.CautionPlayer2Btn;
                theMatch.sendOffCode.subOffButton = theMatch.awaySubOff.SubOffPlayer2Btn;
            }

            //Carry out the actual sending off
            sendOffPlayer();  
        }

        //This method is run when the third player in the team is being sent off
        private void SendOffPlayer3Btn_Click(object sender, EventArgs e)
        {
            //Get hold of the id of the player being sent off, from the button that
            //was clicked
            player_id = Int32.Parse(SendOffPlayer3Btn.Tag.ToString());

            //This code is run if the home team are having a player sent off
            if (homeOrAway.Equals("home"))
            {
                //Indicate which buttons on other screens need to be updated
                //to reflect the sending off
                theMatch.sendOffCode.sendOffButton = this.SendOffPlayer3Btn;
                theMatch.sendOffCode.goalButton = theMatch.homeGoal.GoalPlayer3Btn;
                theMatch.sendOffCode.cautionButton = theMatch.homeCaution.CautionPlayer3Btn;
                theMatch.sendOffCode.subOffButton = theMatch.homeSubOff.SubOffPlayer3Btn;
            }
            //This code is run if the away team are having a player sent off
            else
            {
                //Indicate which buttons on other screens need to be updated
                //to reflect the sending off
                theMatch.sendOffCode.sendOffButton = this.SendOffPlayer3Btn;
                theMatch.sendOffCode.goalButton = theMatch.awayGoal.GoalPlayer3Btn;
                theMatch.sendOffCode.cautionButton = theMatch.awayCaution.CautionPlayer3Btn;
                theMatch.sendOffCode.subOffButton = theMatch.awaySubOff.SubOffPlayer3Btn;
            }

            //Carry out the actual sending off
            sendOffPlayer();  
        }

        //This method is run when the fourth player in the team is being sent off
        private void SendOffPlayer4Btn_Click(object sender, EventArgs e)
        {
            //Get hold of the id of the player being sent off, from the button that
            //was clicked
            player_id = Int32.Parse(SendOffPlayer4Btn.Tag.ToString());

            //This code is run if the home team are having a player sent off
            if (homeOrAway.Equals("home"))
            {
                //Indicate which buttons on other screens need to be updated
                //to reflect the sending off
                theMatch.sendOffCode.sendOffButton = this.SendOffPlayer4Btn;
                theMatch.sendOffCode.goalButton = theMatch.homeGoal.GoalPlayer4Btn;
                theMatch.sendOffCode.cautionButton = theMatch.homeCaution.CautionPlayer4Btn;
                theMatch.sendOffCode.subOffButton = theMatch.homeSubOff.SubOffPlayer4Btn;
            }
            //This code is run if the away team are having a player sent off
            else
            {
                //Indicate which buttons on other screens need to be updated
                //to reflect the sending off
                theMatch.sendOffCode.sendOffButton = this.SendOffPlayer4Btn;
                theMatch.sendOffCode.goalButton = theMatch.awayGoal.GoalPlayer4Btn;
                theMatch.sendOffCode.cautionButton = theMatch.awayCaution.CautionPlayer4Btn;
                theMatch.sendOffCode.subOffButton = theMatch.awaySubOff.SubOffPlayer4Btn;
            }

            //Carry out the actual sending off
            sendOffPlayer();  
        }

        //This method is run when the fifth player in the team is being sent off
        private void SendOffPlayer5Btn_Click(object sender, EventArgs e)
        {
            //Get hold of the id of the player being sent off, from the button that
            //was clicked
            player_id = Int32.Parse(SendOffPlayer5Btn.Tag.ToString());

            //This code is run if the home team are having a player sent off
            if (homeOrAway.Equals("home"))
            {
                //Indicate which buttons on other screens need to be updated
                //to reflect the sending off
                theMatch.sendOffCode.sendOffButton = this.SendOffPlayer5Btn;
                theMatch.sendOffCode.goalButton = theMatch.homeGoal.GoalPlayer5Btn;
                theMatch.sendOffCode.cautionButton = theMatch.homeCaution.CautionPlayer5Btn;
                theMatch.sendOffCode.subOffButton = theMatch.homeSubOff.SubOffPlayer5Btn;
            }
            //This code is run if the away team are having a player sent off
            else
            {
                //Indicate which buttons on other screens need to be updated
                //to reflect the sending off
                theMatch.sendOffCode.sendOffButton = this.SendOffPlayer5Btn;
                theMatch.sendOffCode.goalButton = theMatch.awayGoal.GoalPlayer5Btn;
                theMatch.sendOffCode.cautionButton = theMatch.awayCaution.CautionPlayer5Btn;
                theMatch.sendOffCode.subOffButton = theMatch.awaySubOff.SubOffPlayer5Btn;
            }

            //Carry out the actual sending off
            sendOffPlayer();  
        }

        //This method is run when the sixth player in the team is being sent off
        private void SendOffPlayer6Btn_Click(object sender, EventArgs e)
        {
            //Get hold of the id of the player being sent off, from the button that
            //was clicked
            player_id = Int32.Parse(SendOffPlayer6Btn.Tag.ToString());

            //This code is run if the home team are having a player sent off
            if (homeOrAway.Equals("home"))
            {
                //Indicate which buttons on other screens need to be updated
                //to reflect the sending off
                theMatch.sendOffCode.sendOffButton = this.SendOffPlayer6Btn;
                theMatch.sendOffCode.goalButton = theMatch.homeGoal.GoalPlayer6Btn;
                theMatch.sendOffCode.cautionButton = theMatch.homeCaution.CautionPlayer6Btn;
                theMatch.sendOffCode.subOffButton = theMatch.homeSubOff.SubOffPlayer6Btn;
            }
            //This code is run if the away team are having a player sent off
            else
            {
                //Indicate which buttons on other screens need to be updated
                //to reflect the sending off
                theMatch.sendOffCode.sendOffButton = this.SendOffPlayer6Btn;
                theMatch.sendOffCode.goalButton = theMatch.awayGoal.GoalPlayer6Btn;
                theMatch.sendOffCode.cautionButton = theMatch.awayCaution.CautionPlayer6Btn;
                theMatch.sendOffCode.subOffButton = theMatch.awaySubOff.SubOffPlayer6Btn;
            }

            //Carry out the actual sending off
            sendOffPlayer();  
        }

        //This method is run when the seventh player in the team is being sent off
        private void SendOffPlayer7Btn_Click(object sender, EventArgs e)
        {
            //Get hold of the id of the player being sent off, from the button that
            //was clicked
            player_id = Int32.Parse(SendOffPlayer7Btn.Tag.ToString());

            //This code is run if the home team are having a player sent off
            if (homeOrAway.Equals("home"))
            {
                //Indicate which buttons on other screens need to be updated
                //to reflect the sending off
                theMatch.sendOffCode.sendOffButton = this.SendOffPlayer7Btn;
                theMatch.sendOffCode.goalButton = theMatch.homeGoal.GoalPlayer7Btn;
                theMatch.sendOffCode.cautionButton = theMatch.homeCaution.CautionPlayer7Btn;
                theMatch.sendOffCode.subOffButton = theMatch.homeSubOff.SubOffPlayer7Btn;
            }
            //This code is run if the away team are having a player sent off
            else
            {
                //Indicate which buttons on other screens need to be updated
                //to reflect the sending off
                theMatch.sendOffCode.sendOffButton = this.SendOffPlayer7Btn;
                theMatch.sendOffCode.goalButton = theMatch.awayGoal.GoalPlayer7Btn;
                theMatch.sendOffCode.cautionButton = theMatch.awayCaution.CautionPlayer7Btn;
                theMatch.sendOffCode.subOffButton = theMatch.awaySubOff.SubOffPlayer7Btn;
            }

            //Carry out the actual sending off
            sendOffPlayer();  
        }

        //This method is run when the eighth player in the team is being sent off
        private void SendOffPlayer8Btn_Click(object sender, EventArgs e)
        {
            //Get hold of the id of the player being sent off, from the button that
            //was clicked
            player_id = Int32.Parse(SendOffPlayer8Btn.Tag.ToString());

            //This code is run if the home team are having a player sent off
            if (homeOrAway.Equals("home"))
            {
                //Indicate which buttons on other screens need to be updated
                //to reflect the sending off
                theMatch.sendOffCode.sendOffButton = this.SendOffPlayer8Btn;
                theMatch.sendOffCode.goalButton = theMatch.homeGoal.GoalPlayer8Btn;
                theMatch.sendOffCode.cautionButton = theMatch.homeCaution.CautionPlayer8Btn;
                theMatch.sendOffCode.subOffButton = theMatch.homeSubOff.SubOffPlayer8Btn;
            }
            //This code is run if the away team are having a player sent off
            else
            {
                //Indicate which buttons on other screens need to be updated
                //to reflect the sending off
                theMatch.sendOffCode.sendOffButton = this.SendOffPlayer8Btn;
                theMatch.sendOffCode.goalButton = theMatch.awayGoal.GoalPlayer8Btn;
                theMatch.sendOffCode.cautionButton = theMatch.awayCaution.CautionPlayer8Btn;
                theMatch.sendOffCode.subOffButton = theMatch.awaySubOff.SubOffPlayer8Btn;
            }

            //Carry out the actual sending off
            sendOffPlayer();  
        }

        //This method is run when the ninth player in the team is being sent off
        private void SendOffPlayer9Btn_Click(object sender, EventArgs e)
        {
            //Get hold of the id of the player being sent off, from the button that
            //was clicked
            player_id = Int32.Parse(SendOffPlayer9Btn.Tag.ToString());

            //This code is run if the home team are having a player sent off
            if (homeOrAway.Equals("home"))
            {
                //Indicate which buttons on other screens need to be updated
                //to reflect the sending off
                theMatch.sendOffCode.sendOffButton = this.SendOffPlayer9Btn;
                theMatch.sendOffCode.goalButton = theMatch.homeGoal.GoalPlayer9Btn;
                theMatch.sendOffCode.cautionButton = theMatch.homeCaution.CautionPlayer9Btn;
                theMatch.sendOffCode.subOffButton = theMatch.homeSubOff.SubOffPlayer9Btn;
            }
            //This code is run if the away team are having a player sent off
            else
            {
                //Indicate which buttons on other screens need to be updated
                //to reflect the sending off
                theMatch.sendOffCode.sendOffButton = this.SendOffPlayer9Btn;
                theMatch.sendOffCode.goalButton = theMatch.awayGoal.GoalPlayer9Btn;
                theMatch.sendOffCode.cautionButton = theMatch.awayCaution.CautionPlayer9Btn;
                theMatch.sendOffCode.subOffButton = theMatch.awaySubOff.SubOffPlayer9Btn;
            }

            //Carry out the actual sending off
            sendOffPlayer();  
        }

        //This method is run when the tenth player in the team is being sent off
        private void SendOffPlayer10Btn_Click(object sender, EventArgs e)
        {
            //Get hold of the id of the player being sent off, from the button that
            //was clicked
            player_id = Int32.Parse(SendOffPlayer10Btn.Tag.ToString());

            //This code is run if the home team are having a player sent off
            if (homeOrAway.Equals("home"))
            {
                //Indicate which buttons on other screens need to be updated
                //to reflect the sending off
                theMatch.sendOffCode.sendOffButton = this.SendOffPlayer10Btn;
                theMatch.sendOffCode.goalButton = theMatch.homeGoal.GoalPlayer10Btn;
                theMatch.sendOffCode.cautionButton = theMatch.homeCaution.CautionPlayer10Btn;
                theMatch.sendOffCode.subOffButton = theMatch.homeSubOff.SubOffPlayer10Btn;
            }
            //This code is run if the away team are having a player sent off
            else
            {
                //Indicate which buttons on other screens need to be updated
                //to reflect the sending off
                theMatch.sendOffCode.sendOffButton = this.SendOffPlayer10Btn;
                theMatch.sendOffCode.goalButton = theMatch.awayGoal.GoalPlayer10Btn;
                theMatch.sendOffCode.cautionButton = theMatch.awayCaution.CautionPlayer10Btn;
                theMatch.sendOffCode.subOffButton = theMatch.awaySubOff.SubOffPlayer10Btn;
            }

            //Carry out the actual sending off
            sendOffPlayer();  
        }

        //This method is run when the eleventh player in the team is being sent off
        private void SendOffPlayer11Btn_Click(object sender, EventArgs e)
        {
            //Get hold of the id of the player being sent off, from the button that
            //was clicked
            player_id = Int32.Parse(SendOffPlayer11Btn.Tag.ToString());

            //This code is run if the home team are having a player sent off
            if (homeOrAway.Equals("home"))
            {
                //Indicate which buttons on other screens need to be updated
                //to reflect the sending off
                theMatch.sendOffCode.sendOffButton = this.SendOffPlayer11Btn;
                theMatch.sendOffCode.goalButton = theMatch.homeGoal.GoalPlayer11Btn;
                theMatch.sendOffCode.cautionButton = theMatch.homeCaution.CautionPlayer11Btn;
                theMatch.sendOffCode.subOffButton = theMatch.homeSubOff.SubOffPlayer11Btn;
            }
            //This code is run if the away team are having a player sent off
            else
            {
                //Indicate which buttons on other screens need to be updated
                //to reflect the sending off
                theMatch.sendOffCode.sendOffButton = this.SendOffPlayer11Btn;
                theMatch.sendOffCode.goalButton = theMatch.awayGoal.GoalPlayer11Btn;
                theMatch.sendOffCode.cautionButton = theMatch.awayCaution.CautionPlayer11Btn;
                theMatch.sendOffCode.subOffButton = theMatch.awaySubOff.SubOffPlayer11Btn;
            }

            //Carry out the actual sending off
            sendOffPlayer();  
        }

        //This method is run when the 'Cancel' button is clicked
        private void CancelButton_Click(object sender, EventArgs e)
        {
            //Hide this screen to display the main Match screen
            this.Visible = false;
        }
    }
}